(function(){
	
	var p="=";
	var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	
	function bytes2int(bytes){
		if(bytes.length!=4){
			throw new Error("bytes length must be 4");
		}
		var num = 0;
		var bit = 24;
		for(var i=0;i<bytes.length;i++){
			num += bytes[i] << bit;
			bit -= 8;
		}
		return num;
	}
	
	function base64decode(str){			
		var s=str.split(""), out=[];
		var l=s.length;		
		while(s[--l]==p){ }
		for (var i=0; i<l;){
			var t=tab.indexOf(s[i++])<<18;
			if(i<=l){ t|=tab.indexOf(s[i++])<<12 };
			if(i<=l){ t|=tab.indexOf(s[i++])<<6 };
			if(i<=l){ t|=tab.indexOf(s[i++]) };
			out.push((t>>>16)&0xff);
			out.push((t>>>8)&0xff);
			out.push(t&0xff);
		}
		while(out[out.length-1]==0){ out.pop(); }
		return out;
	};

	var fdfs = {
		decode:function(id){
			var strs = id.split("/");
			var group = strs.shift();
			var name = strs.pop();
			var path = strs.join("/");
			var bytes = base64decode(name);	
			
			var server = bytes.slice(0,4).join(".");
			var time = bytes2int(bytes.slice(4,8));
			var size = bytes2int(bytes.slice(12,16));
			
			return {
				id:id,
				name:name,
				path:path,
				group:group,
				server:server,
				time:time*1000,
				size:size
			};
		}
	};
	
	window.fdfs = fdfs;
})();